home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / DVIM72-Mac 1.9.6 / source / dialogs.c < prev    next >
Encoding:
Text File  |  1992-09-14  |  2.5 KB  |  98 lines  |  [TEXT/R*ch]

  1. /* external prototypes */
  2. void    Do_update(        WindowPtr  where );
  3. Boolean Cancel_key( EventRecord *theEvent );
  4.  
  5. /* internal prototypes */
  6. pascal Boolean Dialog_filter( DialogPtr the_dialog,
  7.                             EventRecord *the_event,
  8.                             int            *item_number );
  9.  
  10. ControlHandle    Get_Ditem_handle( DialogPtr theDialog, int item_no );
  11. void Flash_button( DialogPtr the_dialog, short item_number );
  12.  
  13. enum {
  14.     return_char = 0x0D,
  15.     enter_char = 0x03
  16. };
  17.  
  18. void Flash_button( DialogPtr the_dialog, short item_number )
  19. {
  20.     ControlHandle    item_h;
  21.     long    time;
  22.     short    itype;
  23.     Rect    box;
  24.     
  25.     GetDItem( the_dialog, item_number, &itype, (Handle *)&item_h, &box );
  26.     HiliteControl( item_h, inButton );
  27.     Delay( 9L, &time );
  28.     HiliteControl( item_h, 0 );
  29. }
  30.  
  31. /* ------------------------- Dialog_filter ------------------------ */
  32. pascal Boolean Dialog_filter( DialogPtr the_dialog,
  33.                             EventRecord *the_event,
  34.                             int            *item_number )
  35. {
  36.     int        charcode;
  37.     char    the_char;
  38.     
  39.     if ( (the_event->what == updateEvt) &&
  40.         ((WindowPtr)the_event->message != the_dialog) )
  41.     {
  42.         Do_update( (WindowPtr)the_event->message );
  43.         return( FALSE );
  44.     }
  45.     
  46.     /* We'll only mess with keyDown events. */
  47.     if (the_event->what != keyDown)
  48.         return( FALSE );
  49.     
  50.     charcode = the_event->message & charCodeMask;
  51.     the_char = (char)charcode;
  52.  
  53.     if ( (the_char == return_char) || (the_char == enter_char) )
  54.     {
  55.         *item_number = 1;    /* OK */
  56.         Flash_button( the_dialog, *item_number );
  57.         return( TRUE );
  58.     }
  59.     
  60.     if ( Cancel_key( the_event ) )
  61.     {
  62.         *item_number = 2;    /* Cancel */
  63.         Flash_button( the_dialog, *item_number );
  64.         return( TRUE );
  65.     }
  66.     
  67.     /* The following assumes that editing operations apply to disabled
  68.        editText items.  Thus we don't want ModalDialog to return, so the
  69.        filter changes the event to a null event and returns FALSE.
  70.     */
  71.     if (the_event->modifiers & cmdKey)
  72.     {
  73.         switch (charcode)
  74.         {
  75.             case 'x':
  76.                 *item_number = ((DialogPeek)the_dialog)->editField + 1; /* current text box */
  77.                 DlgCut( the_dialog );
  78.                 the_event->what = 0;    /* Change it to a null event */
  79.                 return( FALSE );
  80.                 break;
  81.             case 'c':
  82.                 *item_number = ((DialogPeek)the_dialog)->editField + 1; /* current text box */
  83.                 DlgCopy( the_dialog );
  84.                 the_event->what = 0;    /* Change it to a null event */
  85.                 return( FALSE );
  86.                 break;
  87.             case 'v':
  88.                 *item_number = ((DialogPeek)the_dialog)->editField + 1; /* current text box */
  89.                 DlgPaste( the_dialog );
  90.                 the_event->what = 0;    /* Change it to a null event */
  91.                 return( FALSE );
  92.                 break;
  93.         }
  94.     }
  95.     else
  96.         return( FALSE );    /* ordinary keystroke */
  97. }
  98.